define_extension :revision, :local_only do
  set(:real_revision) do
    head_rev = (exists?(:scm) && exists?(:revision) && revision == scm.head) 
    prev_rev = build_repository.revisions.reverse.find { |rev| (head_rev ? true : rev == revision) && build_repository[rev].setup? && br[rev].checked_out}

    raise "suitable previous revision not found" unless prev_rev
    prev_rev
  end
end

define_extension :revision, :local_only_with_fallback do
  set(:real_revision) do
    head_rev = (exists?(:scm) && exists?(:revision) && revision == scm.head) 
    prev_rev = build_repository.revisions.reverse.find { |rev| (head_rev ? true : rev == revision) && build_repository[rev].setup? && br[rev].checked_out}    
    
    prev_rev ? prev_rev : fetch_previous
  end
end
